using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] arr = new int[n];
 
        for (int i = 0; i < n; i++)
        {
            arr[i] = int.Parse(Console.ReadLine());
        }
 
        for (int j = 0; j < n; j++)
        {
            int p = arr[j];
 
            string temp = ToBinary(p);
            string reversed = "";
            string mirrored = "";
            for (int i = 0; i < temp.Length; i++)
            {
                if (temp.Substring(i, 1) == "1")
                {
                    reversed = reversed + "0";
                }
                else
                {
                    reversed = reversed + "1";
                }
            }
            int p_reversed = ToDecimal(reversed);
 
            for (int i = temp.Length - 1; i >= 0; i--)
            {
                mirrored = mirrored + temp.Substring(i, 1);
            }
 
            int p_mirrored = ToDecimal(mirrored);
 
            Console.WriteLine((p ^ p_reversed) & p_mirrored);
 
 
        }
         
    }
 
 
 
 
 
 
 
    public static string ToBinary(Int64 Decimal)
    {
        // Declare a few variables we're going to need
        Int64 BinaryHolder;
        char[] BinaryArray;
        string BinaryResult = "";
 
        while (Decimal > 0)
        {
            BinaryHolder = Decimal % 2;
            BinaryResult += BinaryHolder;
            Decimal = Decimal / 2;
        }
 
        // The algoritm gives us the binary number in reverse order (mirrored)
        // We store it in an array so that we can reverse it back to normal
        BinaryArray = BinaryResult.ToCharArray();
        Array.Reverse(BinaryArray);
        BinaryResult = new string(BinaryArray);
 
        return BinaryResult;
    }
 
    public static int ToDecimal(string bin)
    {
        long l = Convert.ToInt64(bin, 2);
        int i = (int)l;
        return i;
    }
}